package com.tjdr.his.drugstore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjdr.his.domain.entity.DrugInfo;
import com.tjdr.his.domain.mapper.IDrugInfoMapper;
import com.tjdr.his.drugstore.service.IDrugInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @AUTHOR 张三
 * @DATE 2024/10/16 10:47
 * @DESCRIBER
 */
@Service("drugService")
public class IDrugInfoServiceImpl implements IDrugInfoService {
    @Autowired
    private IDrugInfoMapper mapper;

    @Override
    public boolean insertOrupdateDrugById(DrugInfo drugInfo) {
       return  mapper.insertOrUpdate(drugInfo);

    }

    @Override
    public IPage selectDrugsByProperties(DrugInfo drugInfo, int pageSize, int currentPage) {
        IPage<DrugInfo> page = new Page();
        page.setSize(pageSize);
        page.setCurrent(currentPage);
        LambdaQueryWrapper<DrugInfo> lambdaQueryWrapper = new QueryWrapper<DrugInfo>().lambda();
        lambdaQueryWrapper
                .eq(DrugInfo::getDrugType,drugInfo.getDrugType())
                .like(DrugInfo::getDrugName,drugInfo.getDrugName()==null?"":drugInfo.getDrugName())
                .like(DrugInfo::getMnemonicCode,drugInfo.getMnemonicCode()==null?"":drugInfo.getMnemonicCode());
        return mapper.selectPage(page,lambdaQueryWrapper);

    }


}
